package com.demo.demospringbootstarter.conf;

import com.demo.demospringbootstarter.business.SmsService;
import com.demo.demospringbootstarter.business.impl.AliCloudSmsServiceImpl;
import com.demo.demospringbootstarter.business.impl.TxCloudSmsServiceImpl;
import com.demo.demospringbootstarter.entity.DemoProperties;
import com.demo.demospringbootstarter.service.DemoService;
import com.demo.demospringbootstarter.service.SmsTemplate;
import com.demo.demospringbootstarter.service.TestService;
import com.demo.demospringbootstarter.service.impl.TestServiceImpl;
import com.demo.demospringbootstarter.util.spring.ApplicationContextHolder;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

@AutoConfiguration
@ConditionalOnClass(DemoService.class)
@EnableConfigurationProperties(value = DemoProperties.class)
public class DemoAutoConfiguration {

    @Bean("tx")
    public SmsService txCloudSmsService(){
        return new TxCloudSmsServiceImpl();
    }
    @Bean("ali")
    public SmsService aliCloudSmsService(){
        return new AliCloudSmsServiceImpl();
    }

    @Bean
    @ConditionalOnMissingBean
    public DemoService demoService(){
        return new DemoService();
    }

    @Bean
    @ConditionalOnMissingBean
    public TestService testService(){
        return new TestServiceImpl();
    }

    @Bean
    public SmsTemplate smsTemplate(){
        return new SmsTemplate();
    }
    @Bean(name = "suchtool.niceutil.applicationContextHolder")
    public ApplicationContextHolder applicationContextHolder() {
        return new ApplicationContextHolder();
    }
}
